﻿namespace Test_ISuperList
{
    using System;
    using DymanicArray;
    using NUnit.Framework;

    [TestFixture(typeof(MyDynList))]
    [TestFixture(typeof(MyList))]
    public class Test<TSuperList> where TSuperList : ISuperList, new()
    {
        [SetUp]
        public void Set()
        {
            this.list = new TSuperList();
        }

        [TearDown]
        public void CleanUp()
        {
            list.Clear();
        }

        /// <summary>
        /// Add Elements Test
        /// </summary>
        /// <param name="list">My list</param>
        //[TestCaseSource("myLists")]
        [Test]
        public void UT_AddElements()
        {
            Init(list, 10);
            Assert.IsTrue(list.Compare(x));
        }

        /// <summary>
        /// Get Element Test
        /// </summary>
        /// <param name="list">My list</param>
        [Test]
        public void UT_GetElement()
        {
            list.Add(2);
            Assert.AreEqual(2, list.GetItem(0));
        }

        /// <summary>
        /// Catch Exception Test
        /// </summary>
        /// <param name="list">My list</param>
        [Test]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void UT_ExceptionGetItem()
        {
            list.GetItem(100);
        }

        /// <summary>
        /// Count Test
        /// </summary>
        /// <param name="size">Amount of Elements in list</param>
        [Test]
        public void UT_GetCount([Values(0, 1, 25, 100)]int size)
        {
            Init(list, size);
            Assert.AreEqual(size, list.Count);
        }

        [Test]
        public void UT_GetEnumerator()
        {
            string actual = string.Empty, expected = "44132141323413224132";
            x = new int[] { 1, 2, 3, 4 };
            for (int i = 0; i < x.Length; i++)
            {
                list.Add(x[i]);
            }

            foreach (var p in list)
            {
                actual += p.ToString();
                foreach (var p2 in list)
                {
                    actual += p2.ToString();
                }
            }

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        /// Initialize my list with random values
        /// </summary>
        /// <param name="list">My list</param>
        /// <param name="amount">Amount of elements</param>
        private void Init(ISuperList l, int amount)
        {
            x = new int[amount];
            for (int i = 0; i < amount; i++)
            {
                x[i] = rand.Next(100);
                l.Add(x[i]);
            }

        }

        Random rand = new Random();
        ISuperList list;
        //ISuperList[] myLists = { new MyList(), new MyDynList() };
        int[] x;
    }
}
